﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using eTMS.Controllers;

namespace eTMS.Forms.Students
{
    public partial class FrmSinhVienAddNew : eTMS.Controls.BaseForm
    {
        public FrmSinhVienAddNew()
        {
            InitializeComponent();
        }

        private SinhVienController controller;
        public void SetAddNew(SinhVienController sinhVienController)
        {
            controller = sinhVienController;
            sinhVienInfoInput1.SetController(controller);
            lyLichSinhVienInfo1.SetController(controller);
            controller.ResetLyLichSinhVien();
            controller.ResetObject();
            lyLichSinhVienInfo1.UpdateToScreen();
            sinhVienInfoInput1.UpdateToScreen();
        }
        public void SetAddEdit(SinhVienController sinhVienController)
        {
            controller = sinhVienController;
            sinhVienInfoInput1.SetController(controller);
            lyLichSinhVienInfo1.SetController(controller);
            controller.LoadLyLichSinhVien();
            lyLichSinhVienInfo1.UpdateToScreen();
            sinhVienInfoInput1.UpdateToScreen();
        }

        private void ucCommandDialog1_OnOK(object sender, CancelEventArgs e)
        {
            sinhVienInfoInput1.UpdateToModel();
            lyLichSinhVienInfo1.UpdateToModel();
            bool result = false;
            if (controller.SinhVienObject.SinhVien_ID == 0)
            {
                result = controller.AddNew();
            }
            else
            {
                result = controller.Update();
            }
            if (result)
                controller.SaveLyLichSinhVien();
        }
    }
}
